/****************************************************************************\
*                                                                            *
*  Copyright 2008 The CAnt2 Project (http://code.google.com/p/cant2)         *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
\****************************************************************************/

#ifndef INCLUDED_MINIXMLDOM_H__
#define INCLUDED_MINIXMLDOM_H__

#include "StringPool.h"
#include "ValuePtr.h"
#include "xml.h"

namespace MiniXmlDOM {

    struct StringWithSource
    {
        StringPool::Handle handle;
        int sourceLine;
        int sourceColumn;

        StringWithSource ( const wchar_t* value );

        void Swap ( StringWithSource& other );
    };

    struct Attribute
    {
        StringWithSource name;
        StringWithSource value;
        ValuePtr<Attribute> nextAttribute;

        Attribute ( const StringWithSource& name, const StringWithSource& value );

        void Swap ( Attribute& other );

    private:
        Attribute ( const Attribute& );
        Attribute& operator = ( const Attribute& );
    };

    struct Element
    {        
        StringWithSource name;
        ValuePtr<Attribute> firstAttribute;
        ValuePtr<Element> firstChild;
        ValuePtr<Element> nextSibling;

        Element ( const StringWithSource& name );

        void Swap ( Element& other );

    private:
        Element ( const Element& );
        Element& operator = ( const Element& );
    };

    struct Document
    {
        Document();
        StringPool::Handle fileNameHandle;
        ValuePtr<Element> firstChild;

        void Swap ( Document& other );

    private:
        Document ( const Document& );
        Document& operator = ( const Document& );
    };

    class DocumentFactory : public IXmlParseEvent
    {
    public:
        DocumentFactory();
        ~DocumentFactory();

        void Get ( Document& );

    public:
        virtual void ElementBegin ( const wchar_t* name );
        virtual void ElementEnd   ( const wchar_t* name );
        virtual void Attribute    ( const wchar_t* name, const wchar_t* value );
        virtual void ElementEndAttributes ( const wchar_t* name );
        virtual void EndOfFile    ();

    private:
        DocumentFactory( const DocumentFactory& );
        DocumentFactory& operator = ( const DocumentFactory& );

    private:
        class Details;
        std::auto_ptr < Details > pimpl;
    };
}

#endif /* #ifndef INCLUDED_MINIXMLDOM_H__ */

